<%@include file="include_top.jspf"%>
<%String filter = (String) request.getAttribute("filter");%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>BidPirate - List Bids</title>
</head>
<body>
<script>
    function confirmAndDelete(description, id) {
        if (confirm("Delete \"" + description + "\"?")) {
            window.location.href = "listBids_deleteBid.html?id=" + id;
        }
    }
	jQuery(function() {
		$("span.ACTIVE,span.WATCH").each(function(index) {
			var priceSpan = $(this);
			var bidId = $(priceSpan).attr("id");
			$.getJSON("listBids_getItemPrice.json?bidId=" + bidId, function(itemPrice) {
				if (itemPrice.updated) {
					$(priceSpan).fadeOut().fadeIn().fadeOut(function() {
						$(this).text(itemPrice.currency + itemPrice.newPrice).fadeIn();
					});
				}
			});
		});
	});
</script>
<c:if test="${not userSession.loggedIn && not empty pager.pageResults}">
<p class="info">Log in with your eBay account to save and activate your bids.</p>
</c:if>
<table style="text-align: center;">
    <thead>
        <tr>
        	<th width="100"></th>
        	<th width="240">Description</th>
        	<th width="120">Price</th>
        	<th width="120">Bid</th>
        	<th width="120">End</th>
        	<th width="100">Status</th>
        	<th width="40">:</th>
        	<th width="80">
	        	<form method="get">
	        		<select name="filter" onchange="submit()" style="background:none;border:0">
	        			<option <%=filter.equals("all")?"selected='selected'":""%>>all</option>
	        			<option <%=filter.equals("live")?"selected='selected'":""%>>live</option>
	        			<option <%=filter.equals("won")?"selected='selected'":""%>>won</option>
	        		</select>
	        		<input type="hidden" name="page" value="1"/>
	        	</form>
        	</th>
        </tr>
    </thead>
	<tbody>    
<c:forEach items="${pager.pageResults}" var="bid">
		<tr>
			<td><img src="${bid.item.imageUrl}" width="100"/></td>
			<td>
				<a href="${fn:replace(openItemUrl,'%ITEM_NUMBER%',bid.item.itemNumber)}" target="ebay" title="Open in eBay">${bid.item.description}</a>
<c:if test="${bid.inGroup}">
				<span class="group">${bid.group}</span>
</c:if>
			</td>
			<td>
<c:if test="${not bid.completed}">
				<span class="${bid.status}" id="${bid.id}">${bid.item.currency}<fmt:formatNumber pattern="#,##0.00" value="${bid.item.price}"/></span>
</c:if>
<c:if test="${bid.completed}">
				<b>${bid.item.currency}<fmt:formatNumber pattern="#,##0.00" value="${bid.item.price}"/></b>
</c:if>
			</td>
			<td>
<c:if test="${not empty bid.maxBid}">
				${bid.item.currency}<fmt:formatNumber pattern="#,##0.00" value="${bid.maxBid}"/>
</c:if>
<c:if test="${bid.item.buyItNow}">
				<i style="font-size: smaller;">Buy It <font color="red">Now</font></i>
</c:if>
			
			</td>
			<td><joda:format pattern="E dd MMM HH:mm z" dateTimeZone="${userSession.user.region.timeZone}" value="${bid.item.endTime}"/></td>
			<td>
				<i>${fn:toLowerCase(bid.status)}</i>
			</td>
			<td class="left">
<c:if test="${bid.status=='WON'}">
				<img src="static/won.gif"/> 
</c:if>	
<c:if test="${bid.status=='LOST'}">
				<img src="static/lost.gif"/> 
</c:if>	
			</td>
			<td>
<c:if test="${bid.updatable && not bid.item.buyItNow}">			
				<input type="button" value="Edit" class="fill" onclick="location.href='editBid.html?id=${bid.id}'"/>
</c:if>				
				<input type="button" value="Delete" class="fill" <c:if test="${bid.status=='BIDDING'}">disabled="disabled"</c:if> onclick="confirmAndDelete('<spring:message text="${bid.item.description}" htmlEscape="true" javaScriptEscape="true"/>','${bid.id}')"/>
			</td>
		</tr>
</c:forEach>
    </tbody>
</table>
<c:if test="${pager.show}">
<p align="center">${pager.html}</p>
</c:if>
</body>
</html>
